const path = require('path')
const merge = require('webpack-merge');

const resolve = dir => {
    return path.join(__dirname, dir)
}
const baseConfig = require('./config/index');
// yarn serve --p aaa
const project = process.argv[process.argv.length-1];
if(process.argv[process.argv.length-2] !== '--p'){
    console.error("命令错误")
    console.error("启动 yarn serve --p 【项目名】")
    console.error("编译 yarn build --p 【项目名】")
    console.error("编译 yarn analyzer --p 【项目名】")
    return
}

module.exports = merge(baseConfig,{
    publicPath:  `/${project}`,
    pages: {
        index: {
            // 入口文件
            entry: `projects/${project}/main.js`, /*这个是根入口文件*/
            // 模板文件
            template: `projects/${project}/index.html`,
            // 输出文件
            filename: 'index.html',
            // 页面title
            title: 'Index Page'
        },
        // subpage: `projects/${project}/main.js` /*注意这个是*/
    },
    outputDir: `dist/${project}`,
    lintOnSave: 'error',
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src')) // key,value自行定义，比如.set('@@', resolve('src/components'))
    },
    devServer: {
        port:9090,
        overlay: {
            warnings: true,
            errors: true
        },
    },
    // 设为false打包时不生成.map文件
    productionSourceMap: false
})
